Skip to content

feat: support :global{} & :local{} for css module#1

Merged
elrrrrrrr merged 9 commits intomasterfrom
support-css-module-global
Oct 30, 2025
Merged

feat: support :global{} & :local{} for css module#1
elrrrrrrr merged 9 commits intomasterfrom
support-css-module-global

Conversation

@fireairforce
Copy link

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CSS Modules feature by implementing support for the non-functional :global and :local pseudo-classes. This change allows for a more intuitive and streamlined way to define global and local styling contexts within CSS Modules, particularly when dealing with nested selectors, by automatically interpreting these pseudo-classes with a nesting selector argument.

Highlights

  • CSS Modules Support: Introduced support for non-functional :local and :global pseudo-classes within CSS Modules. These are now implicitly treated as functional pseudo-classes, specifically :local(&) and :global(&), allowing them to correctly affect nested rules blocks.
  • Error Handling Refinement: Removed the previous error condition that would trigger when :local or :global were used without arguments in CSS Modules, as these cases are now explicitly handled as valid syntax.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for non-functional :global and :local pseudo-classes for CSS modules, which is a great feature enhancement. The implementation is straightforward, handling these cases in parse_non_ts_pseudo_class and removing the previous error-handling logic. I have one suggestion to reduce some code duplication, but otherwise, the changes look good.

src/selector.rs Outdated
Comment on lines +107 to +108
"local" if self.options.css_modules.is_some() => Local { selector: Box::new(Selector::from(Component::Nesting)) },
"global" if self.options.css_modules.is_some() => Global { selector: Box::new(Selector::from(Component::Nesting)) },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two match arms are very similar. You can combine them into a single arm to reduce code duplication and improve maintainability.

      "local" | "global" if self.options.css_modules.is_some() => {
        let selector = Box::new(Selector::from(Component::Nesting));
        if name.eq_ignore_ascii_case("local") {
          Local { selector }
        } else {
          Global { selector }
        }
      },

- Add serialize_selector_with_css_modules and serialize_component_with_css_modules functions
- Pass handle_css_modules parameter to control CSS modules processing
- In :global context, skip CSS modules hashing for class names and IDs
- Fixes issue where :global { .class } was incorrectly hashed
- Remove the !combinators_exhausted condition that was causing assertion failure
- This was incorrectly copied from the original implementation
- Remove serialize_selector_old and serialize_component_old functions
- These were causing combinators_exhausted assertion failures
- Keep only the working implementations
- Remove combinators_exhausted variable and its assertion
- This was causing assertion failures in selector serialization
- The logic was incorrect and not needed for the CSS modules fix
- Add :global( and ) wrapper around the selector content
- This ensures the output matches CSS Modules specification
- The inner selector should not be hashed when inside :global()
…selector chains

- Pass mutable handle_css_modules through selector/component serializers
- When encountering :global, disable hashing for the rest of the chain
- Keep :local to serialize inner selector with hashing on
- Output :global(...) wrapper explicitly
- Detect implicit non-functional :global alias (:global(&))
- Do not emit wrapper, just disable hashing for the rest of the chain
- Preserve explicit :global(<selector>) in output
@elrrrrrrr elrrrrrrr merged commit e9ffd58 into master Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants